package com.google.android.material.appbar;

import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewParent;
import android.widget.FrameLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import com.google.android.material.appbar.AppBarLayout.c;
import o.ah;
import o.aqu.f;
import o.aqu.j;
import o.aqu.n;
import o.aqv;
import o.ard;
import o.arw;
import o.ary;
import o.asa;
import o.fo;
import o.gg;
import o.gr;
import o.gz;
import o.hx;
import o.ij;

public class CollapsingToolbarLayout extends FrameLayout {
    private View ʻ;
    private boolean ʻॱ;
    private Toolbar ʼ;
    private int ʽ;
    private c ʽॱ;
    private int ʾ;
    private long ˈ;
    final ary ˊ;
    private final Rect ˊॱ;
    ij ˋ;
    private int ˋॱ;
    Drawable ˎ;
    int ˏ;
    private int ˏॱ;
    private boolean ͺ;
    private boolean ॱ;
    private int ॱˊ;
    private ValueAnimator ॱˋ;
    private boolean ॱˎ;
    private int ॱॱ;
    private int ॱᐝ;
    private View ᐝ;
    private Drawable ᐝॱ;

    public static class LayoutParams extends android.widget.FrameLayout.LayoutParams {
        float ˊ = 0.5f;
        int ˏ = 0;

        public LayoutParams(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, n.ॱﹳ);
            this.ˏ = obtainStyledAttributes.getInt(n.ॱﾞ, 0);
            ˎ(obtainStyledAttributes.getFloat(n.ॱꜞ, 0.5f));
            obtainStyledAttributes.recycle();
        }

        public LayoutParams(int i, int i2) {
            super(i, i2);
        }

        public LayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
        }

        public void ˎ(float f) {
            this.ˊ = f;
        }
    }

    class b implements c {
        final /* synthetic */ CollapsingToolbarLayout ˋ;

        b(CollapsingToolbarLayout collapsingToolbarLayout) {
            this.ˋ = collapsingToolbarLayout;
        }

        public void ˊ(AppBarLayout appBarLayout, int i) {
            int ˎ;
            this.ˋ.ˏ = i;
            if (this.ˋ.ˋ != null) {
                ˎ = this.ˋ.ˋ.ˎ();
            } else {
                ˎ = 0;
            }
            int childCount = this.ˋ.getChildCount();
            for (int i2 = 0; i2 < childCount; i2++) {
                View childAt = this.ˋ.getChildAt(i2);
                LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams();
                ard ˋ = CollapsingToolbarLayout.ˋ(childAt);
                switch (layoutParams.ˏ) {
                    case 1:
                        ˋ.ˎ(gr.ॱ(-i, 0, this.ˋ.ˎ(childAt)));
                        break;
                    case 2:
                        ˋ.ˎ(Math.round(layoutParams.ˊ * ((float) (-i))));
                        break;
                    default:
                        break;
                }
            }
            this.ˋ.ॱ();
            if (this.ˋ.ˎ != null && ˎ > 0) {
                ViewCompat.ˎ(this.ˋ);
            }
            this.ˋ.ˊ.ˏ(((float) Math.abs(i)) / ((float) ((this.ˋ.getHeight() - ViewCompat.ˋॱ(this.ˋ)) - ˎ)));
        }
    }

    protected /* synthetic */ android.view.ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return ˎ();
    }

    protected /* synthetic */ android.widget.FrameLayout.LayoutParams m6generateDefaultLayoutParams() {
        return ˎ();
    }

    protected /* synthetic */ android.view.ViewGroup.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
        return ˋ(layoutParams);
    }

    public CollapsingToolbarLayout(Context context) {
        this(context, null);
    }

    public CollapsingToolbarLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public CollapsingToolbarLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ॱ = true;
        this.ˊॱ = new Rect();
        this.ʾ = -1;
        this.ˊ = new ary(this);
        this.ˊ.ˋ(aqv.ˋ);
        TypedArray ॱ = asa.ॱ(context, attributeSet, n.ߴ, i, f.ᐝ, new int[0]);
        this.ˊ.ˎ(ॱ.getInt(n.ॱᶥ, 8388691));
        this.ˊ.ॱ(ॱ.getInt(n.ॱᐧ, 8388627));
        int dimensionPixelSize = ॱ.getDimensionPixelSize(n.ॱʾ, 0);
        this.ˏॱ = dimensionPixelSize;
        this.ˋॱ = dimensionPixelSize;
        this.ॱˊ = dimensionPixelSize;
        this.ॱॱ = dimensionPixelSize;
        if (ॱ.hasValue(n.ॱʿ)) {
            this.ॱॱ = ॱ.getDimensionPixelSize(n.ॱʿ, 0);
        }
        if (ॱ.hasValue(n.ॱˈ)) {
            this.ˋॱ = ॱ.getDimensionPixelSize(n.ॱˈ, 0);
        }
        if (ॱ.hasValue(n.ߵ)) {
            this.ॱˊ = ॱ.getDimensionPixelSize(n.ߵ, 0);
        }
        if (ॱ.hasValue(n.ॱـ)) {
            this.ˏॱ = ॱ.getDimensionPixelSize(n.ॱـ, 0);
        }
        this.ͺ = ॱ.getBoolean(n.ॱꜟ, true);
        setTitle(ॱ.getText(n.ߺ));
        this.ˊ.ˋ(f.ˎ);
        this.ˊ.ˊ(ah.f.ˎ);
        if (ॱ.hasValue(n.ॱˑ)) {
            this.ˊ.ˋ(ॱ.getResourceId(n.ॱˑ, 0));
        }
        if (ॱ.hasValue(n.ॱˌ)) {
            this.ˊ.ˊ(ॱ.getResourceId(n.ॱˌ, 0));
        }
        this.ʾ = ॱ.getDimensionPixelSize(n.ॱᐨ, -1);
        this.ˈ = (long) ॱ.getInt(n.ॱㆍ, 600);
        setContentScrim(ॱ.getDrawable(n.ॱˍ));
        setStatusBarScrim(ॱ.getDrawable(n.ॱˉ));
        this.ʽ = ॱ.getResourceId(n.ॱꓸ, -1);
        ॱ.recycle();
        setWillNotDraw(false);
        ViewCompat.ˋ(this, new hx(this) {
            final /* synthetic */ CollapsingToolbarLayout ॱ;

            {
                this.ॱ = r1;
            }

            public ij ˋ(View view, ij ijVar) {
                return this.ॱ.ˏ(ijVar);
            }
        });
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ViewParent parent = getParent();
        if (parent instanceof AppBarLayout) {
            ViewCompat.ˎ(this, ViewCompat.ॱˋ((View) parent));
            if (this.ʽॱ == null) {
                this.ʽॱ = new b(this);
            }
            ((AppBarLayout) parent).ˋ(this.ʽॱ);
            ViewCompat.ᐝॱ(this);
        }
    }

    protected void onDetachedFromWindow() {
        ViewParent parent = getParent();
        if (this.ʽॱ != null && (parent instanceof AppBarLayout)) {
            ((AppBarLayout) parent).ˎ(this.ʽॱ);
        }
        super.onDetachedFromWindow();
    }

    ij ˏ(ij ijVar) {
        ij ijVar2 = null;
        if (ViewCompat.ॱˋ(this)) {
            ijVar2 = ijVar;
        }
        if (!gz.ˏ(this.ˋ, ijVar2)) {
            this.ˋ = ijVar2;
            requestLayout();
        }
        return ijVar.ॱॱ();
    }

    public void draw(Canvas canvas) {
        super.draw(canvas);
        ˋ();
        if (this.ʼ == null && this.ᐝॱ != null && this.ॱᐝ > 0) {
            this.ᐝॱ.mutate().setAlpha(this.ॱᐝ);
            this.ᐝॱ.draw(canvas);
        }
        if (this.ͺ && this.ॱˎ) {
            this.ˊ.ˊ(canvas);
        }
        if (this.ˎ != null && this.ॱᐝ > 0) {
            int ˎ = this.ˋ != null ? this.ˋ.ˎ() : 0;
            if (ˎ > 0) {
                this.ˎ.setBounds(0, -this.ˏ, getWidth(), ˎ - this.ˏ);
                this.ˎ.mutate().setAlpha(this.ॱᐝ);
                this.ˎ.draw(canvas);
            }
        }
    }

    protected boolean drawChild(Canvas canvas, View view, long j) {
        boolean z;
        if (this.ᐝॱ == null || this.ॱᐝ <= 0 || !ˏ(view)) {
            z = false;
        } else {
            this.ᐝॱ.mutate().setAlpha(this.ॱᐝ);
            this.ᐝॱ.draw(canvas);
            z = true;
        }
        if (super.drawChild(canvas, view, j) || r0) {
            return true;
        }
        return false;
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        if (this.ᐝॱ != null) {
            this.ᐝॱ.setBounds(0, 0, i, i2);
        }
    }

    private void ˋ() {
        if (this.ॱ) {
            this.ʼ = null;
            this.ʻ = null;
            if (this.ʽ != -1) {
                this.ʼ = (Toolbar) findViewById(this.ʽ);
                if (this.ʼ != null) {
                    this.ʻ = ॱ(this.ʼ);
                }
            }
            if (this.ʼ == null) {
                Toolbar toolbar;
                int childCount = getChildCount();
                for (int i = 0; i < childCount; i++) {
                    View childAt = getChildAt(i);
                    if (childAt instanceof Toolbar) {
                        toolbar = (Toolbar) childAt;
                        break;
                    }
                }
                toolbar = null;
                this.ʼ = toolbar;
            }
            ᐝ();
            this.ॱ = false;
        }
    }

    private boolean ˏ(View view) {
        return (this.ʻ == null || this.ʻ == this) ? view == this.ʼ : view == this.ʻ;
    }

    private View ॱ(View view) {
        CollapsingToolbarLayout parent = view.getParent();
        View view2 = view;
        while (parent != this && parent != null) {
            if (parent instanceof View) {
                view2 = parent;
            }
            parent = parent.getParent();
        }
        return view2;
    }

    private void ᐝ() {
        if (!(this.ͺ || this.ᐝ == null)) {
            ViewParent parent = this.ᐝ.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(this.ᐝ);
            }
        }
        if (this.ͺ && this.ʼ != null) {
            if (this.ᐝ == null) {
                this.ᐝ = new View(getContext());
            }
            if (this.ᐝ.getParent() == null) {
                this.ʼ.addView(this.ᐝ, -1, -1);
            }
        }
    }

    protected void onMeasure(int i, int i2) {
        ˋ();
        super.onMeasure(i, i2);
        int mode = MeasureSpec.getMode(i2);
        int ˎ = this.ˋ != null ? this.ˋ.ˎ() : 0;
        if (mode == 0 && ˎ > 0) {
            super.onMeasure(i, MeasureSpec.makeMeasureSpec(ˎ + getMeasuredHeight(), 1073741824));
        }
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int ˎ;
        int childCount;
        int i5;
        int i6 = 1;
        int i7 = 0;
        super.onLayout(z, i, i2, i3, i4);
        if (this.ˋ != null) {
            ˎ = this.ˋ.ˎ();
            childCount = getChildCount();
            for (i5 = 0; i5 < childCount; i5++) {
                View childAt = getChildAt(i5);
                if (!ViewCompat.ॱˋ(childAt) && childAt.getTop() < ˎ) {
                    ViewCompat.ʽ(childAt, ˎ);
                }
            }
        }
        if (this.ͺ && this.ᐝ != null) {
            boolean z2 = ViewCompat.ˋˊ(this.ᐝ) && this.ᐝ.getVisibility() == 0;
            this.ॱˎ = z2;
            if (this.ॱˎ) {
                if (ViewCompat.ʼ(this) != 1) {
                    i6 = 0;
                }
                ˎ = ˎ(this.ʻ != null ? this.ʻ : this.ʼ);
                arw.ˏ((ViewGroup) this, this.ᐝ, this.ˊॱ);
                this.ˊ.ˎ(this.ˊॱ.left + (i6 != 0 ? this.ʼ.ॱ() : this.ʼ.ˊ()), this.ʼ.ˏ() + (this.ˊॱ.top + ˎ), (i6 != 0 ? this.ʼ.ˊ() : this.ʼ.ॱ()) + this.ˊॱ.right, (ˎ + this.ˊॱ.bottom) - this.ʼ.ˋ());
                ary o_ary = this.ˊ;
                i5 = i6 != 0 ? this.ˋॱ : this.ॱॱ;
                childCount = this.ˊॱ.top + this.ॱˊ;
                int i8 = i3 - i;
                if (i6 != 0) {
                    i6 = this.ॱॱ;
                } else {
                    i6 = this.ˋॱ;
                }
                o_ary.ॱ(i5, childCount, i8 - i6, (i4 - i2) - this.ˏॱ);
                this.ˊ.ॱॱ();
            }
        }
        i5 = getChildCount();
        while (i7 < i5) {
            ˋ(getChildAt(i7)).ˏ();
            i7++;
        }
        if (this.ʼ != null) {
            if (this.ͺ && TextUtils.isEmpty(this.ˊ.ᐝ())) {
                setTitle(this.ʼ.ˊॱ());
            }
            if (this.ʻ == null || this.ʻ == this) {
                setMinimumHeight(ˊ(this.ʼ));
            } else {
                setMinimumHeight(ˊ(this.ʻ));
            }
        }
        ॱ();
    }

    private static int ˊ(@NonNull View view) {
        android.view.ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (!(layoutParams instanceof MarginLayoutParams)) {
            return view.getHeight();
        }
        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams;
        return marginLayoutParams.bottomMargin + (view.getHeight() + marginLayoutParams.topMargin);
    }

    static ard ˋ(View view) {
        ard o_ard = (ard) view.getTag(j.ॱˋ);
        if (o_ard != null) {
            return o_ard;
        }
        o_ard = new ard(view);
        view.setTag(j.ॱˋ, o_ard);
        return o_ard;
    }

    public void setTitle(@Nullable CharSequence charSequence) {
        this.ˊ.ˋ(charSequence);
        ʽ();
    }

    @Nullable
    public CharSequence ˊ() {
        return this.ͺ ? this.ˊ.ᐝ() : null;
    }

    public void setTitleEnabled(boolean z) {
        if (z != this.ͺ) {
            this.ͺ = z;
            ʽ();
            ᐝ();
            requestLayout();
        }
    }

    public void setScrimsShown(boolean z) {
        boolean z2 = ViewCompat.ˊᐝ(this) && !isInEditMode();
        setScrimsShown(z, z2);
    }

    public void setScrimsShown(boolean z, boolean z2) {
        int i = 255;
        if (this.ʻॱ != z) {
            if (z2) {
                if (!z) {
                    i = 0;
                }
                ˎ(i);
            } else {
                if (!z) {
                    i = 0;
                }
                ˏ(i);
            }
            this.ʻॱ = z;
        }
    }

    private void ˎ(int i) {
        ˋ();
        if (this.ॱˋ == null) {
            this.ॱˋ = new ValueAnimator();
            this.ॱˋ.setDuration(this.ˈ);
            this.ॱˋ.setInterpolator(i > this.ॱᐝ ? aqv.ˏ : aqv.ˎ);
            this.ॱˋ.addUpdateListener(new AnimatorUpdateListener(this) {
                final /* synthetic */ CollapsingToolbarLayout ˊ;

                {
                    this.ˊ = r1;
                }

                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    this.ˊ.ˏ(((Integer) valueAnimator.getAnimatedValue()).intValue());
                }
            });
        } else if (this.ॱˋ.isRunning()) {
            this.ॱˋ.cancel();
        }
        this.ॱˋ.setIntValues(new int[]{this.ॱᐝ, i});
        this.ॱˋ.start();
    }

    void ˏ(int i) {
        if (i != this.ॱᐝ) {
            if (!(this.ᐝॱ == null || this.ʼ == null)) {
                ViewCompat.ˎ(this.ʼ);
            }
            this.ॱᐝ = i;
            ViewCompat.ˎ(this);
        }
    }

    public void setContentScrim(@Nullable Drawable drawable) {
        Drawable drawable2 = null;
        if (this.ᐝॱ != drawable) {
            if (this.ᐝॱ != null) {
                this.ᐝॱ.setCallback(null);
            }
            if (drawable != null) {
                drawable2 = drawable.mutate();
            }
            this.ᐝॱ = drawable2;
            if (this.ᐝॱ != null) {
                this.ᐝॱ.setBounds(0, 0, getWidth(), getHeight());
                this.ᐝॱ.setCallback(this);
                this.ᐝॱ.setAlpha(this.ॱᐝ);
            }
            ViewCompat.ˎ(this);
        }
    }

    public void setContentScrimColor(@ColorInt int i) {
        setContentScrim(new ColorDrawable(i));
    }

    public void setContentScrimResource(@DrawableRes int i) {
        setContentScrim(fo.ˊ(getContext(), i));
    }

    public void setStatusBarScrim(@Nullable Drawable drawable) {
        Drawable drawable2 = null;
        if (this.ˎ != drawable) {
            if (this.ˎ != null) {
                this.ˎ.setCallback(null);
            }
            if (drawable != null) {
                drawable2 = drawable.mutate();
            }
            this.ˎ = drawable2;
            if (this.ˎ != null) {
                if (this.ˎ.isStateful()) {
                    this.ˎ.setState(getDrawableState());
                }
                gg.ˏ(this.ˎ, ViewCompat.ʼ(this));
                this.ˎ.setVisible(getVisibility() == 0, false);
                this.ˎ.setCallback(this);
                this.ˎ.setAlpha(this.ॱᐝ);
            }
            ViewCompat.ˎ(this);
        }
    }

    protected void drawableStateChanged() {
        super.drawableStateChanged();
        int[] drawableState = getDrawableState();
        int i = 0;
        Drawable drawable = this.ˎ;
        if (drawable != null && drawable.isStateful()) {
            i = 0 | drawable.setState(drawableState);
        }
        drawable = this.ᐝॱ;
        if (drawable != null && drawable.isStateful()) {
            i |= drawable.setState(drawableState);
        }
        if (this.ˊ != null) {
            i |= this.ˊ.ˋ(drawableState);
        }
        if (i != 0) {
            invalidate();
        }
    }

    protected boolean verifyDrawable(Drawable drawable) {
        return super.verifyDrawable(drawable) || drawable == this.ᐝॱ || drawable == this.ˎ;
    }

    public void setVisibility(int i) {
        super.setVisibility(i);
        boolean z = i == 0;
        if (!(this.ˎ == null || this.ˎ.isVisible() == z)) {
            this.ˎ.setVisible(z, false);
        }
        if (this.ᐝॱ != null && this.ᐝॱ.isVisible() != z) {
            this.ᐝॱ.setVisible(z, false);
        }
    }

    public void setStatusBarScrimColor(@ColorInt int i) {
        setStatusBarScrim(new ColorDrawable(i));
    }

    public void setStatusBarScrimResource(@DrawableRes int i) {
        setStatusBarScrim(fo.ˊ(getContext(), i));
    }

    public void setCollapsedTitleTextAppearance(@StyleRes int i) {
        this.ˊ.ˊ(i);
    }

    public void setCollapsedTitleTextColor(@ColorInt int i) {
        setCollapsedTitleTextColor(ColorStateList.valueOf(i));
    }

    public void setCollapsedTitleTextColor(@NonNull ColorStateList colorStateList) {
        this.ˊ.ˊ(colorStateList);
    }

    public void setCollapsedTitleGravity(int i) {
        this.ˊ.ॱ(i);
    }

    public void setExpandedTitleTextAppearance(@StyleRes int i) {
        this.ˊ.ˋ(i);
    }

    public void setExpandedTitleColor(@ColorInt int i) {
        setExpandedTitleTextColor(ColorStateList.valueOf(i));
    }

    public void setExpandedTitleTextColor(@NonNull ColorStateList colorStateList) {
        this.ˊ.ˋ(colorStateList);
    }

    public void setExpandedTitleGravity(int i) {
        this.ˊ.ˎ(i);
    }

    public void setCollapsedTitleTypeface(@Nullable Typeface typeface) {
        this.ˊ.ॱ(typeface);
    }

    public void setExpandedTitleTypeface(@Nullable Typeface typeface) {
        this.ˊ.ˏ(typeface);
    }

    public void setExpandedTitleMargin(int i, int i2, int i3, int i4) {
        this.ॱॱ = i;
        this.ॱˊ = i2;
        this.ˋॱ = i3;
        this.ˏॱ = i4;
        requestLayout();
    }

    public void setExpandedTitleMarginStart(int i) {
        this.ॱॱ = i;
        requestLayout();
    }

    public void setExpandedTitleMarginTop(int i) {
        this.ॱˊ = i;
        requestLayout();
    }

    public void setExpandedTitleMarginEnd(int i) {
        this.ˋॱ = i;
        requestLayout();
    }

    public void setExpandedTitleMarginBottom(int i) {
        this.ˏॱ = i;
        requestLayout();
    }

    public void setScrimVisibleHeightTrigger(@IntRange(from = 0) int i) {
        if (this.ʾ != i) {
            this.ʾ = i;
            ॱ();
        }
    }

    public int ˏ() {
        if (this.ʾ >= 0) {
            return this.ʾ;
        }
        int ˎ = this.ˋ != null ? this.ˋ.ˎ() : 0;
        int ˋॱ = ViewCompat.ˋॱ(this);
        if (ˋॱ > 0) {
            return Math.min(ˎ + (ˋॱ * 2), getHeight());
        }
        return getHeight() / 3;
    }

    public void setScrimAnimationDuration(@IntRange(from = 0) long j) {
        this.ˈ = j;
    }

    protected boolean checkLayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof LayoutParams;
    }

    protected LayoutParams ˎ() {
        return new LayoutParams(-1, -1);
    }

    public android.widget.FrameLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new LayoutParams(getContext(), attributeSet);
    }

    protected android.widget.FrameLayout.LayoutParams ˋ(android.view.ViewGroup.LayoutParams layoutParams) {
        return new LayoutParams(layoutParams);
    }

    final void ॱ() {
        if (this.ᐝॱ != null || this.ˎ != null) {
            setScrimsShown(getHeight() + this.ˏ < ˏ());
        }
    }

    final int ˎ(View view) {
        return ((getHeight() - ˋ(view).ˊ()) - view.getHeight()) - ((LayoutParams) view.getLayoutParams()).bottomMargin;
    }

    private void ʽ() {
        setContentDescription(ˊ());
    }
}
